from jsonpath import jsonpath
from jsonschema import validate
from common.logger import logger


def ass(response, status_code, except_code, except_msg, schema):
    assert response.status_code == status_code
    logger.info("code ==>> 期望结果：{}， 实际结果：{}".format(except_code, response.json().get("code")))
    assert response.json().get("code") == except_code
    print('打印', jsonpath(response.json(), '$..msg')[0], except_msg)
    assert jsonpath(response.json(), '$..msg')[0] == except_msg
    # schema = {
    #     "type": "object",
    #     "properties": {
    #         "code": {"type": "integer"},
    #         "data": {"type": "array"},
    #         "msg": {"type": "string"}
    #     }
    # }
    validate(instance=response.json(), schema=schema)
